﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32.SafeHandles;

namespace DaliUsb
{
  internal static class Kernel32
  {
    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    internal static extern SafeFileHandle CreateFile(
        string fileName,
        [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
        [MarshalAs(UnmanagedType.U4)] FileShare fileShare,
        IntPtr securityAttributes,
        [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
        [MarshalAs(UnmanagedType.U4)] EFileAttributes flags,
        IntPtr template);

    // Get Create File
    [DllImport("kernel32.dll", SetLastError = true)]
    internal static extern IntPtr CreateFile(
        string lpFileName,							// file name
        uint dwDesiredAccess,						// access mode
        uint dwShareMode,							// share mode
        uint lpSecurityAttributes,					// SD
        uint dwCreationDisposition,					// how to create
        uint dwFlagsAndAttributes,					// file attributes
        uint hTemplateFile							// handle to template file
        );

    [DllImport("kernel32.dll")]
    static public extern int WriteFile(SafeFileHandle hFile, ref byte lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, int lpOverlapped);
	
  }
}
